/* 点击滚动到指定部位 */
const clickScroll = () => {
  let olis = document.querySelectorAll(".oli");
  let regard = document.querySelector("#regard")
  let business = document.querySelector("#business")
  let operation = document.querySelector("#operation")
  let framework = document.querySelector("#framework")
  let cooperation = document.querySelector("#cooperation")
  let brief = document.querySelector("#brief")
  let onLineApp = document.querySelector("#onLineApp")
  let bottom = document.querySelector("#bottom")
  for (let i = 0; i < olis.length; i++) {
    olis[i].onclick = function () {
      if (i == 0) {
        window.scrollTo({
          top: 0,
          behavior: "smooth"
        });

      }
      if (i == 1) {
        window.scrollTo({
          top: regard.offsetTop,
          behavior: "smooth"
        });
      }
      if (i == 2) {
        window.scrollTo({
          top: business.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = business.offsetTop; */
      }
      if (i == 3) {
        window.scrollTo({
          top: operation.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = cooperation.offsetTop; */
      }
      if (i == 4) {
        window.scrollTo({
          top: framework.offsetTop,
          behavior: "smooth"
        });
        /*  document.documentElement.scrollTop = document.body.scrollTop = framework.offsetTop; */
      }
      if (i == 5) {
        window.scrollTo({
          top: cooperation.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = cooperation.offsetTop; */
      }
      if (i == 6) {
        window.scrollTo({
          top: brief.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = brief.offsetTop; */
      }
      if (i == 7) {
        window.scrollTo({
          top: onLineApp.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = onLineApp.offsetTop; */
      }
      if (i == 8) {
        window.scrollTo({
          top: bottom.offsetTop,
          behavior: "smooth"
        });
        /* document.documentElement.scrollTop = document.body.scrollTop = bottom.offsetTop; */
      }
      for (let j = 0; j < olis.length; j++) {
        olis[j].classList.remove("navactive");
      }
      olis[i].classList.add("navactive");
    };
  }
}
/* 点击切换app图片 */
const cutPicture = () => {
  let btnas = document.querySelectorAll(".btna");
  let appImg = document.querySelectorAll(".app-img-phone");
  let appTxt = document.querySelectorAll(".app-txt")
  for (let i = 0; i < btnas.length; i++) {
    btnas[i].index = i;//自定义属性 作为下标
    btnas[i].onclick = function () {
      for (let j = 0; j < btnas.length; j++) {
        btnas[j].classList.remove("active");
        appImg[j].style.display = "none";
        appTxt[j].style.display = "none";
      }
      btnas[i].classList.add("active");
      appImg[this.index].style.display = "block";
      appTxt[this.index].style.display = "block";
    };
  }
}
/* 导航栏固定 */
const immobilizationNav= () => {
  let header = document.querySelector("#header")
  let sTop = document.documentElement.scrollTop;
  if (sTop > 50) {
    header.style.position = "fixed";
    header.style.top = 0;
  } else {
    header.style.position = "static";
  }
}
export {
  clickScroll,
  cutPicture,
  immobilizationNav
}